package com.justgame.project.base.support;

import com.justgame.project.cloud.base.entity.CurrentUser;
import com.justgame.project.cloud.common.util.AppContextUtils;
import com.justgame.project.service.system.entity.SysUserInfo;
import com.justgame.project.service.system.feign.ISysUserInfoClient;
import org.apache.shiro.SecurityUtils;
import org.springframework.core.MethodParameter;
import org.springframework.lang.NonNull;
import org.springframework.util.Assert;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

public class    SysUserInfoArgumentResolver implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        return methodParameter.getParameterType() == CurrentUser.class;
    }

    @Override
    public CurrentUser resolveArgument(@NonNull MethodParameter methodParameter,
                                  ModelAndViewContainer modelAndViewContainer,
                                  @NonNull NativeWebRequest nativeWebRequest,
                                  WebDataBinderFactory webDataBinderFactory) throws Exception {
        Object userObj = SecurityUtils.getSubject().getPrincipal();
        Assert.notNull(userObj,"请先登录后再试");
        return (CurrentUser)userObj;
    }
}
